package StudyCode.summary.mydatetime;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.Locale;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class MonthDayYear {
	public static void main(String[] args) {
		System.out.println("中国格式化结果:");
		LocalDate localDate = LocalDate.now();
		format(localDate, "M/d/yyyy");
		format(localDate, "MM/dd/yyyy");
		format(localDate, "MMM dd, yyyy");
		format(localDate, "MMMM dd, yyyy");

		System.out.println("美国格式化结果:");
		formatUS(localDate, "M/d/yyyy");
		formatUS(localDate, "MM/dd/yyyy");
		formatUS(localDate, "MMM dd, yyyy");
		formatUS(localDate, "MMMM dd, yyyy");
	}

	private static void format(Temporal co, String pattern) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern);
		String str = fmt.format(co);
		System.out.println(pattern + ": " + str);
	}

	private static void formatUS(Temporal co, String pattern) {
		DateTimeFormatter fmt = DateTimeFormatter.ofPattern(pattern, Locale.US);
		String str = fmt.format(co);
		System.out.println(pattern + ": " + str);
	}
}
